package kr.ac.kongju.gedl.search.web;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import kr.ac.kongju.gedl.cmmn.web.CU;
import kr.ac.kongju.gedl.common.util.ListResultVO;
import kr.ac.kongju.gedl.item.service.ItemService;
import kr.ac.kongju.gedl.item.vo.ItemVO;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.support.SessionStatus;

import egovframework.rte.fdl.property.EgovPropertyService;
import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;

@Controller
public class SearchController {

	/** EgovPropertyService */
	@Resource(name = "propertiesService")
	protected EgovPropertyService propertiesService;

	@Resource(name = "itemService")
	protected ItemService itemService;
	

	@RequestMapping(value="/search/resultList.do")
	public String selectSearchResultList(@ModelAttribute("searchVO") ItemVO searchVO,
			ModelMap model, SessionStatus status, HttpSession session) throws Exception {
		
    	ListResultVO<ItemVO> resultList = itemService.retrieveItemList(searchVO);
		
    	//페이징을 구성한다
    	PaginationInfo paginationInfo = new PaginationInfo();

		paginationInfo.setCurrentPageNo(searchVO.getPage());
		paginationInfo.setRecordCountPerPage(searchVO.getRowPerPage());
		paginationInfo.setPageSize(searchVO.getPageSize());

		paginationInfo.setTotalRecordCount(resultList.getListCount());
    	
    	model.addAttribute("searchVO", searchVO);
		model.addAttribute("resultList", resultList);
		model.addAttribute("paginationInfo", paginationInfo);
		
		session.setAttribute("totalSearchWord", searchVO.getTotalSearchWord());
		
		return "/search/searchResultList";
	}
	
	@RequestMapping(value="/search/detailSearch.do")
	public String detailSearch(@ModelAttribute("searchVO") ItemVO searchVO,
			ModelMap model, SessionStatus status, HttpSession session) throws Exception {
		
		
		model.addAttribute("searchVO", searchVO);
		model.addAttribute("regionList1", CU.getInstance().getCodeList("REGION"));
		
		return "/search/detailSearch";
	}
	
	




}
